/*
 * Title: WADS
 * Description: Web-based Auto flow Documents System
 * Copyright: 2007
 * Company: CoE
 * @author: Mr.Nattasan Wang-Aphisit
 * @version 1.1
 */

package wads.app;

import wads.drawing.node.CaseNode;
//import java.awt.Font;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;

public abstract class BaseWADDialog extends JDialog {

//  protected Properties properties;
  private CaseNode ownerNode;

  private JButton okBtn = new JButton("OK");
  private JButton cancelBtn = new JButton("Cancel");
  private JPanel buttonsPanel = new JPanel();
  
  private static final int HEIGHT_DECREASE = 90;

  public abstract void initDisplay();
  public abstract void saveProperties();

//  public void setProperties(Properties new_properties){
//    this.properties = new_properties;
//  }
//
//  public Properties getProperties(){
//    return this.properties;
//  }

  public BaseWADDialog(Frame parent, CaseNode own){
    super(parent);
    ownerNode = own;
    try {
      jbInit();
    }
    catch(Exception e) { e.printStackTrace(); }
  }

  private void jbInit() throws Exception {
    okBtn.setActionCommand("okBtn");
//    okBtn.setFont(new Font("Tahoma", Font.PLAIN, 13));
    okBtn.setBounds(new Rectangle(30, 10, 80, 27));
    okBtn.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        okBtn_actionPerformed(e);
      }
    });

    cancelBtn.setActionCommand("cancelBtn");
//    cancelBtn.setFont(new Font("Tahoma", Font.PLAIN, 13));
    cancelBtn.setBounds(new Rectangle(125, 10, 80, 27));
    cancelBtn.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        cancelBtn_actionPerformed(e);
      }
    });

    this.getContentPane().setLayout(null);
    buttonsPanel.setLayout(null);
    buttonsPanel.add(cancelBtn, null);
    buttonsPanel.add(okBtn, null);
    this.getContentPane().add(buttonsPanel, null);
    this.setModal(true);
    this.setResizable(false);
  }

  private void okBtn_actionPerformed(ActionEvent e) {
    saveProperties();
    //getOwnerNode().closeDialog(JOptionPane.OK_OPTION);
    this.dispose();
  }

  private void cancelBtn_actionPerformed(ActionEvent e) {
    this.dispose();
  }
  
  public void setOptionButtonsPanelLocation(int height){
    buttonsPanel.setBounds(new Rectangle(60, height-HEIGHT_DECREASE, 215, 44));
  }

    /**
     * @return the ownerNode
     */
    public CaseNode getOwnerNode() {
        return ownerNode;
    }

    /**
     * @param ownerNode the ownerNode to set
     */
    public void setOwnerNode(CaseNode ownerNode) {
        this.ownerNode = ownerNode;
    }

}